package org.apache.sad.core.framework.utils;

public abstract class MonitoringUtil {
    
    private static final String WEBLOGIC_NAME_KEY = "weblogic.Name";
    private static final String HEART_BEAT_NAME_DELI = ":";    
    
    public static final String TIME_UNIT = "ms.";  
    public static final String MODULE_NAME = "module.name";
    public static final String HEART_BEAT_INIT_OBJECT_NAME = "heartbeat.init.object.name";
    public static final String DEFAULT_HEART_BEAT_INIT_OBJECT_NAME = "eeg.heartbeat.Initializer";
    private static final String MODULE_PROPERTY_NAME = "module=";
        
    private final static String JMX_NAME_SEPERATOR = ",";
        
    public static String mapJmxName2ModuleName(String label) {
        if (label == null) {
            return label;
        }
        
        int index = label.indexOf(MODULE_PROPERTY_NAME);
        if (index == -1) {
            return null;
        } else {
            int begin = index + MODULE_PROPERTY_NAME.length();
            if (begin >= label.length()) {
                return null;
            } else {
                return label.substring(begin);
            }
        }        
    }
        
    public static String createHeartBeatName(String moduleName) {
        StringBuffer sb = new StringBuffer(moduleName);
        sb.append(HEART_BEAT_NAME_DELI);
        sb.append(System.getProperty(WEBLOGIC_NAME_KEY));
        return sb.toString();
    }            

}